/**
 * 
 */
package view;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import java.awt.BorderLayout;
import javax.swing.JTable;
import java.awt.FlowLayout;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;

/**
 * @author hanssonke
 *
 */
public class MainDisplay extends JPanel {

	private static final long serialVersionUID = 1L;
	private VControler vControler;  //  @jve:decl-index=0:
	private JPanel jPanelTable = null;
	private JPanel jPanelSearchFields = null;
	private JPanel jPanelButtons = null;
	private JTextField jTextField = null;
	private JTextField jTextField1 = null;
	private JTextField jTextField2 = null;
	private JTextField jTextField3 = null;
	private JTextField jTextField4 = null;
	private JButton jButtonSearch = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	/**
	 * This is the default constructor
	 */
	public MainDisplay() {
		super();
		initialize();
	}

	public MainDisplay(VControler controler) {
		super();
		initialize();
		this.vControler = controler;
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setSize(680, 445);
		this.setPreferredSize(new Dimension(0, 0));
		this.add(getJPanelTable(), null);
		this.add(getJPanelSearchFields(), null);
		this.add(getJPanelButtons(), null);
		this.addComponentListener(new java.awt.event.ComponentAdapter() {
			public void componentShown(java.awt.event.ComponentEvent e) {
				vControler.populateTable();
				System.out.println("componentShown()"); // TODO Auto-generated Event stub componentShown()
				validate();
			}
		});
		this.setSize(new Dimension(650, 402));
	}

	/**
	 * This method initializes jPanelTable	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelTable() {
		if (jPanelTable == null) {
			jPanelTable = new JPanel();
			jPanelTable.setLayout(new BorderLayout());
			jPanelTable.setPreferredSize(new Dimension(0, 0));
			jPanelTable.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jPanelTable;
	}

	/**
	 * This method initializes jPanelSearchFields	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelSearchFields() {
		if (jPanelSearchFields == null) {
			jPanelSearchFields = new JPanel();
			jPanelSearchFields.setLayout(new FlowLayout());
			jPanelSearchFields.setPreferredSize(new Dimension(0, 35));
			jPanelSearchFields.add(getJTextField(), null);
			jPanelSearchFields.add(getJTextField1(), null);
			jPanelSearchFields.add(getJTextField2(), null);
			jPanelSearchFields.add(getJTextField3(), null);
			jPanelSearchFields.add(getJTextField4(), null);
			jPanelSearchFields.add(getJButtonSearch(), null);
		}
		return jPanelSearchFields;
	}

	/**
	 * This method initializes jPanelButtons	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelButtons() {
		if (jPanelButtons == null) {
			jPanelButtons = new JPanel();
			jPanelButtons.setLayout(new FlowLayout());
			jPanelButtons.setPreferredSize(new Dimension(0, 35));
		}
		return jPanelButtons;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setPreferredSize(new Dimension(50, 20));
		}
		return jTextField;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setPreferredSize(new Dimension(50, 20));
		}
		return jTextField1;
	}

	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setPreferredSize(new Dimension(50, 20));
		}
		return jTextField2;
	}

	/**
	 * This method initializes jTextField3	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField3() {
		if (jTextField3 == null) {
			jTextField3 = new JTextField();
			jTextField3.setPreferredSize(new Dimension(50, 20));
		}
		return jTextField3;
	}

	/**
	 * This method initializes jTextField4	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField4() {
		if (jTextField4 == null) {
			jTextField4 = new JTextField();
			jTextField4.setPreferredSize(new Dimension(100, 20));
		}
		return jTextField4;
	}

	/**
	 * This method initializes jButtonSearch	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSearch() {
		if (jButtonSearch == null) {
			jButtonSearch = new JButton();
			jButtonSearch.setText("Search");
			jButtonSearch.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					vControler.populateTable();

					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButtonSearch;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
		}
		return jScrollPane;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
